<template>
  <div>
    <el-autocomplete
      v-model="choosedp"
      placeholder="请输入"
      :fetchSuggestions="searcheq"
      style="width:100%"
      clearable
    ></el-autocomplete>

  </div>
</template>

<script>
export default {
  props: {
    selectconfirm: String,
  },
  data() {
    return {
      ts: this.newStore(),
      eqList: [],
      choosedp: '',
    };
  },
  watch: {
    choosedp(newval) {
      if (newval == '') {
        this.$emit('update:selectconfirm', '');
      } else {
        this.$emit('update:selectconfirm', newval);
      }
    },
  },
  created() {
    this.geteqList();
  },
  methods: {
    // 获取设备列表
    geteqList() {
      this.eqList = [];
      const req = {
        handle:
          'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AC6CA23DDA51CC45D66536CEB631F69D9BFF0B9210751F692',
        start: '0',
        limit: '100000',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        for (let index = 0; index < ts.d.data.operation1.length; index += 1) {
          const a = {};
          a.value = ts.d.data.operation1[index].hash.content;
          a.id = ts.d.data.operation1[index].hash.content;
          this.eqList.push(a);
        }
      });
    },
    // 搜索经办人
    searcheq(queryString, cb) {
      const results = queryString
        ? this.eqList.filter(this.createStateFilter(queryString))
        : this.eqList;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 1000 * Math.random());
    },
    createStateFilter(queryString) {
      return eqList => eqList.value.indexOf(queryString) > -1;
    },
    // // 选择经办人后
    // selecteq(val) {
    //   console.log(val);
    //   this.$emit('update:selectconfirm', val);
    // },
  },
};
</script>

<style>
</style>
